package com.example.su_shi_tan_mine.child

import android.content.Context
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.example.su_shi_tan_bas_lib.utils.PixUtils
import com.example.su_shi_tan_mine.R
import com.lxj.xpopup.core.BottomPopupView

class AddPayingWayPop(context: Context) : BottomPopupView(context), View.OnClickListener {

    private var payWay = AddPayingWayFragment.WEI_CHAT_PAY

    fun setPayWay(payWay: Int) {
        this.payWay = payWay
    }

    fun getPayWay() = payWay

    private val weiChatAccount by lazy {
        findViewById<TextView>(R.id.weiChatAccount)
    }

    private val mAliPayAccount by lazy {
        findViewById<TextView>(R.id.AliPayAccount)
    }

    private val mBankCardAccount by lazy {
        findViewById<TextView>(R.id.BankCardAccount)
    }

    private val weiChatAccountIcon by lazy {
        findViewById<ImageView>(R.id.weiChatAccountIcon)
    }

    private val mAliPayAccountIcon by lazy {
        findViewById<ImageView>(R.id.AliPayAccountIcon)
    }

    private val mBankCardIcon by lazy {
        findViewById<ImageView>(R.id.BankCardIcon)
    }

    override fun getImplLayoutId(): Int {
        return R.layout.add_paying_way_pop
    }

    override fun getPopupHeight(): Int {
        return PixUtils.dp2px(200)
    }


    override fun onCreate() {
        super.onCreate()


        weiChatAccount.setOnClickListener(this)


        mAliPayAccount.setOnClickListener(this)

        mBankCardAccount.setOnClickListener(this)

        findViewById<View>(R.id.dismiss).setOnClickListener(this)

        showSelectIcon()
    }

    private fun showSelectIcon() {
        when (payWay) {
            AddPayingWayFragment.WEI_CHAT_PAY -> {
                weiChatAccountIcon.visibility = View.VISIBLE
                mAliPayAccountIcon.visibility = View.GONE
                mBankCardIcon.visibility = View.GONE
            }
            AddPayingWayFragment.A_LI_PAY -> {
                weiChatAccountIcon.visibility = View.GONE
                mAliPayAccountIcon.visibility = View.VISIBLE
                mBankCardIcon.visibility = View.GONE
            }
            AddPayingWayFragment.BANK_CARD_PAY -> {
                weiChatAccountIcon.visibility = View.GONE
                mAliPayAccountIcon.visibility = View.GONE
                mBankCardIcon.visibility = View.VISIBLE
            }
        }
    }

    override fun onClick(v: View?) {
        var temp = payWay
        when (v?.id) {
            R.id.weiChatAccount -> {
                temp = AddPayingWayFragment.WEI_CHAT_PAY
            }
            R.id.AliPayAccount -> {
                temp = AddPayingWayFragment.A_LI_PAY
            }
            R.id.BankCardAccount -> {
                temp = AddPayingWayFragment.BANK_CARD_PAY
            }
            R.id.dismiss -> {

            }
        }
        if (temp != payWay) {
            payWay = temp
            showSelectIcon()
        }

        dismiss()
    }

}